package com.yishusmt.wechatapi.wechatdev.utils;

import com.yishusmt.wechatapi.wechatdev.entity.ProblemEntity;
import com.yishusmt.wechatapi.wechatdev.mapper.ProblemEntityMapper;
import com.yishusmt.wechatapi.wechatdev.mapper.ProblemInfoMapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.validation.constraints.Size;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 *  匹配关键字
 *
 * @author zhangyi
 * @date 2018/8/31 10:23
 */
@Component
public class KeywordUtil {


    @Autowired
    private ProblemInfoMapper problemInfoMapper;

    /**
     * 获取关键字id
     *
     * @param key
     * @return
     */
    public List<Long> keyword(String key){
        //字符串处理
        List<Long> list = new ArrayList<>();
        Set<ProblemEntity> problemEntities = problemInfoMapper.selectAllKeyword();
        problemEntities.stream()
                .filter( e -> StringUtils.contains(
                        key.replace("\t","")
                                .replace("\n","")
                                .replace(" ","")
                                .trim(),e.getDesc()))
                .forEach(d -> list.add(d.getId()));
        return list;
    }
}
